﻿Public Class nuevo_kit
    Dim qry As String
    Dim dataset As New DataSet
    Dim estado As String = "2"
    Dim ubicacionstr As String
    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub btn_aceptar_Click(sender As System.Object, e As System.EventArgs) Handles btn_aceptar.Click

        If ValidarVacio(Me, Me.ErrorProvider1) = True Then
            'estado 1: bodega
            qry = "insert into kit values('" & numero_de_serie.Text & "','" & lote.Text & "','" & estudio.SelectedValue & "','" & estado & "','" & ubicacionstr & "',getdate(),'" & vencimiento.Value & "')"
            'MsgBox(qry)
            Consulta("select count(*)as n from kit where kit_idex='" & numero_de_serie.Text & "'", dataset)
            Dim cant As String = 0
            cant = dataset.Tables("data")(0)(0)
            If cant > 0 Then
                MsgBox("Ya existe el numero de serie, porfavor intente con otro", MsgBoxStyle.Critical)
            Else
                If EjecutaConsulta(qry) Then
                    Label7.Text = Integer.Parse(Label7.Text) + 1
                    man_kits.actualizar()
                    'registro movimiento
                    registro("agregar", login.usuario.id, main.modulo.kit)
                End If
            End If


        End If
    End Sub

    Private Sub nuevo_kit_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        CargarCombobox("select * from bodegas", ubicacion, "bod_nombre", "bod_nombre")
        CargarCombobox("select * from estudios where est_estado='1'", estudio, "est_id", "est_nombre")
        If estudio.Items.Count = 0 Then
            MsgBox("No hay Estudios Disponibles, Ingrese uno antes de continuar", MsgBoxStyle.Information)
            Me.Close()
        End If
        RadioButton2.Checked = True
        ubicacionstr = TextBox1.Text
    End Sub

    Private Sub numero_de_serie_LostFocus(sender As Object, e As System.EventArgs) Handles numero_de_serie.LostFocus
        ValidaExistenteserie(numero_de_serie.Text, numero_de_serie, ErrorProvider1)
    End Sub

    Private Sub estudio_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles estudio.SelectedIndexChanged
        Consulta("select est_direccion from estudios where est_id='" & estudio.SelectedValue & "'", dataset)
        TextBox1.Text = dataset.Tables("data").Rows(0)(0)

    End Sub

    Private Sub RadioButton1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton1.CheckedChanged
        ubicacion.Enabled = True
        TextBox1.Enabled = False

        estado = "2"
    End Sub

    Private Sub RadioButton2_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RadioButton2.CheckedChanged
        ubicacion.Enabled = False
        TextBox1.Enabled = True
        ubicacionstr = TextBox1.Text
        estado = "2"
    End Sub

    Private Sub ubicacion_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ubicacion.SelectedIndexChanged
        ubicacionstr = ubicacion.SelectedValue
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub

End Class